# -*- coding: utf-8 -*-
# Created by zhangyanqi on 2018/4/15

"""
思路：维护一个当前序列段的和，最大序列段的和

时间复杂度： O(n)
"""


class Solution:
    def get_biggest(self, nums):
        """
        得到最大的子序列和
        :param nums: int sequence
        :return: biggest subsequence sum
        """
        max_sum = None
        this_sum = 0
        for i in nums:
            this_sum += i
            if max_sum is None or this_sum > max_sum:
                max_sum = this_sum
            if this_sum < 0:
                this_sum = 0
        return max_sum


if __name__ == "__main__":
    s = Solution()
    biggest = s.get_biggest([-2, 1])
    print(biggest)
